package com.example.jwtauthdemo.service.impl;

import com.example.jwtauthdemo.entity.Homework;
import com.example.jwtauthdemo.mapper.HomeworkMapper;
import com.example.jwtauthdemo.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class HomeworkServiceImpl implements HomeworkService {

    @Autowired
    private HomeworkMapper homeworkMapper;

    @Override
    public List<Homework> getAllHomeworks() {
        return homeworkMapper.findAll();
    }

    @Override
    public int countAllHomeworks() {
        return homeworkMapper.countAll();
    }

    @Override
    public int addHomework(Homework homework) {
        if (homework.getCreateTime() == null) {
            homework.setCreateTime(new Date());
        }
        // 默认为"已发布"状态

        return homeworkMapper.insert(homework);
    }

    @Override
    public Homework getHomeworkById(Long homeworkId) {
        return homeworkMapper.selectById(homeworkId);
    }

    @Override
    public List<Homework> getAllHomeworksWithSubmitCount() {
        return homeworkMapper.findAllWithSubmitCount();
    }
}
